package com.soul.server.controller;

import com.soul.model.vo.UserInfoVo;
import com.soul.server.server.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author mdoya
 * @version 1.0
 * @description: 用户控制层
 */
@Slf4j
@RestController
@RequestMapping("/users")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    /**
     *  用户资料 - 读取
     * @param userID 可是陌生人访问
     * @return
     */
    @GetMapping
    public ResponseEntity find(Long userID){
        UserInfoVo userInfoVo = userInfoService.find(userID);
        System.err.println("用户资料 - 读取    " +userInfoVo);
        return ResponseEntity.ok(userInfoVo);
    }

    /**
     *  用户资料 - 保存(更新用户)
     * @param userInfo 用户对象
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public ResponseEntity updateUser(@RequestBody UserInfoVo userInfo){
        log.info("更新用户:{}",userInfo);
        userInfoService.updateUser(userInfo);
        return ResponseEntity.ok(null);
    }

    /**
     *  互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表
     * @param type 类型
     * @return PageResult<UserInfoVo>
     */
    @GetMapping("/friends/{type}")
    public ResponseEntity findFriendFollowPage(@PathVariable("type") String type,@RequestParam(value = "page",defaultValue = "1") Long page,@RequestParam(value = "pagesize",defaultValue = "10")Long pagesize,String nickname){
        return ResponseEntity.ok(userInfoService.findFriendFollowPage(type,page,pagesize,nickname));
    }

    /**
     *  互相喜欢，喜欢，粉丝 - 统计当前用户
     * @return CountsVo
     */
    @GetMapping("/counts")
    public ResponseEntity counts(){
        return ResponseEntity.ok(userInfoService.counts());
    }
}
